package com.qkl.xiatang.app.workflow.controller;

import com.qkl.xiatang.app.dto.upload.UploadFileWebDTO;
import com.qkl.xiatang.app.utils.Result;
import com.qkl.xiatang.app.web.controller.ControllerHelper;
import com.qkl.xiatang.app.workflow.dto.TaskFunctionRelDto;
import com.qkl.xiatang.app.workflow.service.IWorkFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/{app.baseURL}/workflow")
public class WorkFlowController {

    @Autowired
    private IWorkFlowService workFlowService;

    /**
     * 查询在途的任务实例
     * @return
     * @throws Exception
     */
    @PostMapping("/workflowPage")
    public Result workflowPage(@RequestBody TaskFunctionRelDto taskFunctionRelDto) {
        return workFlowService.workflowPage(taskFunctionRelDto);
    }

    /**
     * 查询在途的任务实例
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnWay")
    public Result workflowPageOnWay(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize) {
        return workFlowService.workflowPageOnWay(pageIndex, pageSize);
    }

    /**
     * 查询在途的任务实例数量
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnWayCount")
    public Result workflowPageOnWayDoneCount() {
        return workFlowService.workflowPageOnWayCount();
    }

    /**
     * 查询在途的任务实例数量（管理员）
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnAdminCount")
    public Result workflowPageOnAdminCount() {
        return workFlowService.workflowPageOnAdminCount();
    }

    /**
     * 查询在途的任务实例（待办）
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnWayDone")
    public Result workflowPageOnWayDone(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize) {
        return workFlowService.workflowPageOnWayDone(pageIndex, pageSize);
    }

    /**
     * 查询在途的任务实例（待办管理员）
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnDone")
    public Result workflowPageOnDone(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize) {
        return workFlowService.workflowPageOnDone(pageIndex, pageSize);
    }

    /**
     * 查询在途的任务实例（待审）
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnWayPending")
    public Result workflowPageOnWayPending(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize) {
        return workFlowService.workflowPageOnWayPending(pageIndex, pageSize);
    }

    /**
     * 查询在途的任务实例（待审管理员）
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnPending")
    public Result workflowPageOnPending(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize) {
        return workFlowService.workflowPageOnPending(pageIndex, pageSize);
    }


    /**
     * 查询在途的任务实例（驳回）
     * @return
     * @throws Exception
     */
    @GetMapping("/workflowPageOnWayReject")
    public Result workflowPageOnWayReject(@RequestParam("pageIndex") int pageIndex, @RequestParam("pageSize") int pageSize) {
        return workFlowService.workflowPageOnWayReject(pageIndex, pageSize);
    }


    /**
     * 查询对应的流程模版信息
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("/selectTaskDetail")
    public Result selectTaskDetail(@RequestParam("id") Integer id) {
        return workFlowService.selectTaskDetail(id);
    }

    /**
     * 二维码查询流程节点
     * @param businessId
     * @param businessKey
     * @return
     */
    @GetMapping("/selectCurrentTask")
    public Result selectCurrentTask(@RequestParam("businessId") String businessId, @RequestParam("businessKey") String businessKey) {
        return workFlowService.selectCurrentTask(businessId, businessKey);
    }

    /**
     * 流程节点审批（完成）
     * @param requestBody
     * @return
     */
    @PostMapping("/complete")
    public Result complete(@RequestBody Map<String, Object> requestBody) {
        return workFlowService.complete(requestBody);
    }

    /**
     * 流程节点审批（驳回）
     * @param requestBody
     * @return
     */
    @PostMapping("/reject")
    public Result reject(@RequestBody Map<String, Object> requestBody) {
        return workFlowService.reject(requestBody);
    }


    /**
     * 流程节点文件上传
     * @param webDTO
     * @return
     */
    @PostMapping("/uploadFile")
    public Result completeUploadFile(@RequestBody UploadFileWebDTO webDTO) {
        return ControllerHelper.toOperateResult(workFlowService.completeUploadFile(webDTO));
    }




}
